import { post, get, put, del } from '../utils/request';

/**
 * 商家管理相关API
 */

// 获取商家列表
export const getMerchantList = (params?: {
  page?: number;
  pageSize?: number;
  status?: string;
  level?: string;
  keyword?: string;
}) => {
  return get('/v1/merchant/list', params);
};

// 获取商家详情
export const getMerchantDetail = (id: string) => {
  return get(`/v1/merchant/${id}`);
};

// 添加商家
export const addMerchant = (data: {
  name: string;
  phone: string;
  email?: string;
  address?: string;
  businessLicense?: string;
  description?: string;
}) => {
  return post('/v1/merchant', data);
};

// 更新商家
export const updateMerchant = (id: string, data: {
  name?: string;
  phone?: string;
  email?: string;
  address?: string;
  businessLicense?: string;
  description?: string;
}) => {
  return put(`/v1/merchant/${id}`, data);
};

// 删除商家
export const deleteMerchant = (id: string) => {
  return del(`/v1/merchant/${id}`);
};

// 商家状态管理
export const updateMerchantStatus = (id: string, status: string) => {
  return put(`/v1/merchant/${id}/status`, { status });
};

// 商家审核
export const auditMerchant = (id: string, auditResult: string, auditNote?: string) => {
  return post(`/v1/merchant/${id}/audit`, { auditResult, auditNote });
};

// 获取商家统计数据
export const getMerchantStats = () => {
  return get('/v1/merchant/stats');
};

// 获取商家身份列表
export const getMerchantIdentityList = () => {
  return post('/v1/merchant/identity/list');
};

// 切换商家身份
export const switchMerchantIdentity = (entityId: number) => {
  return post('/v1/merchant/identity/switch', { identity_id: entityId });
};
